<%-- 
    Document   : lab
    Created on : 2019-2-17, 16:53:57
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    session.setAttribute("url", "../main/user.jsp");
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>        
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/color.css" type="text/css" />
        <link rel="stylesheet" href="../../css/demo.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript">
            
            $.extend($.fn.validatebox.defaults.rules, {
                mobileNum: {//验证手机号   
                    validator: function(value, param) {
                        return /^1[3-8]+\d{9}$/.test(value);
                    },
                    message: '请输入正确的手机号码。'
                },
                telNum: {//既验证手机号，又验证座机号
                    validator: function(value, param) {
                        return /(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^(()|(\d{3}\-))?(1[358]\d{9})$)/.test(value);
                    },
                    message: '请输入正确的电话号码。'
                },
                selectValueRequired: {
                    validator: function(value, param) {
                        //console.info($(param[0]).find("option:contains('" + value + "')").val());
                        return checkComboBoxValue(param[0]);
                    },
                    message: '该输入项为必选项'
                }
            });
            $(document).ready(function() {
                $('#dgstudent').datagrid({
                    height: ($(window).height() - 3) + 'px'
                });
            });
        </script>
    </head>
    <body class="easyui-layout">
        <script type="text/javascript">
            var url;            

            function newStudent() {
                var dd = $('#dgstudent').datagrid('getData')
                $('#dlg').dialog('open').dialog('setTitle', '创建新Web用户');
                $('#fm').form('clear');
                //$('#studentno1').textbox('readonly',false);                
                url = '../../servlet/web/user/Save';
            }

            function resetPassword() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('提示', '您确定重置该人员密码吗？', function(r) {
                        if (r) {
                            $.post('../../servlet/web/user/ResetPassword',
                                    {ID: row.ID}, function(result) {
                                if (result.success) {
                                    $.messager.show({// show error message
                                        title: '提示',
                                        msg: '重置成功'
                                    });
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
            
            function destroyStudent() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('提示', '您确定要删除该Web用户信息吗?', function(r) {
                        if (r) {
                            $.post('../../servlet/web/user/Remove',
                                    {ID: row.ID}, function(result) {
                                if (result.success) {
                                    $('#dgstudent').datagrid('reload');    // reload the user data
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }

            function editStudent() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $('#dlg').dialog('open').dialog('setTitle', '编辑');
                    $('#fm').form('load', row);
                    url = '../../servlet/web/user/Update';
                }
            }
            //分配模块
            function selectFactory() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $('#m3').checkbox('check');
                    $('#dlgFactory').dialog('open').dialog('setTitle', '编辑');
                    $('#fmFactory').form('clear');
                    $('#fmFactory').form('load', row);
                    url = '../../servlet/web/user/UpdateModule';
                }
            }
            function refreshStudent() {
                $('#dgstudent').datagrid('reload');    // reload the user data
            }
            function saveStudent() {
                //alert(url);
                $('#fm').form('submit', {
                    url: url,
                    onSubmit: function() {
                        return $(this).form('validate');
                    },
                    success: function(result) {
                        var result = eval('(' + result + ')');
                        if (result.errorMsg) {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        } else {
                            $('#dlg').dialog('close');        // close the dialog
                            $('#dgstudent').datagrid('reload');    // reload the user data
                        }
                    }
                });
            }
            function saveFactory() {
                //alert(url);
                $('#fmFactory').form('submit', {
                    url: url,
                    onSubmit: function() {
                        return $(this).form('validate');
                    },
                    success: function(result) {
                        var endBraceNo = result.indexOf('}');
                        if(endBraceNo<result.length){
                            result = result.substr(0,endBraceNo+1);
                        }
                        //alert(result);
                        var r = eval('(' + result + ')');
                        if (!(r.success)) {
                            $.messager.show({
                                title: 'Error',
                                msg: r.errorMsg
                            });
                        } else {
                            $('#dlgFactory').dialog('close');        // close the dialog
                            $('#dgstudent').datagrid('reload');    // reload the user data
                        }
                    }
                });
            }
        </script>
        <table id="dgstudent" title="Web用户管理" class="easyui-datagrid"
               url="../../servlet/web/user/Load"
               toolbar="#toolbar"
               rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                <tr>                   
                    <th field="ID" hidden="true">ID</th>
                    <th field="username" width="100">用户名</th>
                    <th field="name" width="120">姓名</th>                    
                    <th field="mobilePhone" width="120">手机号码</th>
                    <th field="modules" width="250">模块</th>
                    <th field="note" width="250">备注</th>
                </tr>
            </thead>
        </table>
        <div id="toolbar">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newStudent()">增加</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editStudent()">修改</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyStudent()">删除</a>
            
            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="refreshStudent()">刷新</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-key" plain="true" onclick="resetPassword()">重置密码</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-factory" plain="true" onclick="selectFactory()">分配模块</a>

        </div>
        <div id="dlg" class="easyui-dialog" style="width:500px;height:350px;padding:5px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">Web用户信息</div>
            <form id="fm" method="post" class="fm"> 
                <div class="fitem" style="display:none" >
                    <label>ID:</label>
                    <input id="ID"  class="easyui-textbox" name="ID"  hidden="true" readonly="true" >
                </div>
                <div class="fitem" >
                    <label>用户名:</label>
                    <input id="username"  class="easyui-textbox" name="username"  required="true">
                </div>
                <div class="fitem">
                    <label>姓名:</label>
                    <input id="name" name="name" class="easyui-textbox"   required="true">
                </div>                
                <div class="fitem">
                    <label>手机号码:</label>
                    <input id="mobilePhone" name="mobilePhone" class="easyui-textbox" data-options="prompt:'请输入正确的手机号码',validType:'mobileNum'" >
                </div>
                
                <div class="fitem">
                    <label>备注:</label>
                    <input name="note" class="easyui-textbox" height="60px" data-options="multiline:true,height:'60px'">
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveStudent()">保存</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>
        <div id="dlgFactory" class="easyui-dialog" style="width:500px;height:320px;padding:5px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">分配模块</div>
            <form id="fmFactory" method="post" class="fm"> 
                <div class="fitem" style="display:none" >
                    <label>ID:</label>
                    <input   class="easyui-textbox" name="ID"  hidden="true" readonly="true" >
                </div>
                <div class="fitem" style="display:none" >
                    <label>用户名:</label>
                    <input   class="easyui-textbox" name="username" readonly="true" >
                </div>
                <div class="fitem" >
                    <label>姓名:</label>
                    <input   class="easyui-textbox" name="name" readonly="true" >
                </div>
               <div class="fitem" >
                    <label>业务查询:</label>
                    <input class="easyui-checkbox" dataoptions="checked:true" name="module" value="01">
                </div>
               <div class="fitem" >
                    <label>业务数据管理:</label>
                    <input class="easyui-checkbox" name="module" value="02">
                </div>
                <div class="fitem" >
                    <label>驻厂员统计:</label>
                    <input id="m3" class="easyui-checkbox" name="module" value="03">
                </div>
                <div class="fitem" >
                    <label>大屏系统:</label>
                    <input class="easyui-checkbox" name="module" value="04">
                </div>
                <div class="fitem" >
                    <label>实时供货系统:</label>
                    <input class="easyui-checkbox" name="module" value="05">
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveFactory()">保存</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgFactory').dialog('close')">取消</a>
        </div>
        <style type="text/css">
            .fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:5px;
            }
            .fitem label{
                display:inline-block;
                width:120px;
            }
            .fitem input{
                width:160px;
            }
        </style>
    </body>
</html>
